// packageIndex/pages/da/da.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseUrl:'',
    corporate: '',
    address: '',
    userName: '',
    idNumber:'',
    phonenumber: '',
    password: '',
    confirmPassword: '',
    errorMessage: ''
  },
  handlePasswordInput: function(e) {
    this.setData({
      password: e.detail.value
    });
  },
  handleConfirmPasswordInput: function(e) {
    this.setData({
      confirmPassword: e.detail.value
    });
  },
  complete: function() {
    const password = this.data.password;
    const confirmPassword = this.data.confirmPassword;
    if (password === '') {
      this.setData({
        errorMessage: '请输入密码'
      });
      return;
    }
    if (password.length < 6 || password.length > 16) {
      this.setData({
        errorMessage: '密码长度必须在 6 到 16 位之间'
      });
      return;
    }
    if (!/^[a-zA-Z0-9]+$/.test(password)) {
      this.setData({
        errorMessage: '密码只能包含字母和数字'
      });
      return;
    }
    if (password!== confirmPassword) {
      this.setData({
        errorMessage: '两次输入的密码不一致'
      });
      return;
    }
    // 密码校验通过，清除错误信息
    this.setData({
      errorMessage: ''
    });
    const baseUrl = this.data.baseUrl //获取本地连接地址
    const userName=this.data.userName
    const corporate=this.data.corporate
    const address=this.data.address
    const idNumber=this.data.idNumber
    const nickName=this.data.userName
    const phonebumber=this.data.phonebumber
    const loginPosition=1
    const balance=0
    const roldId=4
    wx.request({
      url:baseUrl+ '/system/suif',
      data: {
        userName:userName,
        corporate:corporate,
        address:address,
        idNumber:idNumber,
        nickName:nickName,
        phonebumber:phonebumber,
        loginPosition:loginPosition,
        balance:balance,
        roldId:roldId
      },
      method: "POST",
      success: (res) => {
        if(res!=200){
          wx.showToast({
            title: '注册失败！',
            icon: 'none'
          })
        }else{
          wx.redirectTo({
            url: "/packagePersonalCenter/pages/logon/logon",
          })
        }
      },
      fail: (err) => {
        wx.showToast({
          title: '注册失败！',
          icon: 'none'
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const app = getApp();
     this.setData({
      corporate: options.corporate,
      address: options.address,
      userName: options.userName,
      idNumber: options.idNumber,
      phonenumber: options.phonenumber,
    });
    this.setData({
      baseUrl:app.globalConfig.baseUrl,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})